//
// Created by jsjxsy on 2022/8/12.
//
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct ComputerLanguage {
  char *language;
  int year;
} ComputerLanguage;


int main(void) {
  char string[] = "C, 1972; C++, 1983; Java, 1995; Rust, 2010; Kotlin, 2011";
  const char *split = ";";
  char *next;
  int index = 0;
  next = strtok(string, split);
  char *subStr[5];
  ComputerLanguage computer_language[5];
  printf("next=%s\n", next);
  subStr[index] = next;
  printf("subStr=%s\n", subStr[index]);
  while (next) {
    next = strtok(NULL, split);
    if (next) {
      index++;
      subStr[index] = next;
      printf("subStr[%d]=%s\n",index, subStr[index]);
    }
    printf("next=%s\n", next);
  }

  for (int i = 0; i < 5; i++) {
    computer_language[i].language = strtok(subStr[i], ",");
    computer_language[i].year = atoi(strtok(NULL, ","));
    printf("language=%s, year= %d\n", computer_language[i].language, computer_language[i].year);
  }
  return 0;
}
